package cool.mtc.base.plugin.generator.code.model.dto;

import cool.mtc.core.util.StringUtil;
import lombok.Data;

/**
 * @author 明河
 */
@Data
public class DbColumnDTO {
    private Integer orderIndex;
    private String columnName;
    private String columnType;
    private String dataType;
    private Boolean nullable;
    private String comment;

    private String key;
    private String field;
    private String javaType;

    public String getKey() {
        return this.getColumnName();
    }

    public String getField() {
        if (StringUtil.isEmpty(this.getColumnName())) {
            return null;
        }
        if (this.getColumnName().startsWith("is_")) {
            return StringUtil.lineToHump(this.getColumnName().replaceFirst("is_", ""));
        }
        return StringUtil.lineToHump(this.getColumnName());
    }

    public String getJavaType() {
        if (StringUtil.isEmpty(this.getDataType())) {
            return StringUtil.EMPTY;
        }
        switch (this.getDataType()) {
            case "char":
            case "varchar":
            case "text":
            case "longtext":
            case "blob":
            case "longblob":
            case "json":
                return "String";
            case "tinyint":
                return "Boolean";
            case "smallint":
            case "int":
                return "Integer";
            case "bigint":
                return "Long";
            case "datetime":
            case "time":
            case "timestamp":
                return "Date";
        }
        return StringUtil.EMPTY;
    }
}
